home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Development Tools & Languages / Bits o' MacApp Code / Light Gray Adorner / TLightGrayAdorner.cp next >
Encoding:
Text File  |  1993-06-10  |  4.2 KB  |  133 lines  |  [TEXT/MPS ]

  1. #include <MacApp.h>
  2.  
  3. #include "TLightGrayAdorner.h"
  4.  
  5. //----------------------------------------------------------------------------------------
  6. // TLtGrayAdorner::Initialize:
  7. //----------------------------------------------------------------------------------------
  8. #pragma segment MAAdornerNonRes
  9. pascal void TLtGrayAdorner::Initialize()
  10. {
  11.     inherited::Initialize();
  12.     fLtGrayPat = nil;
  13.     fWhitePat = nil;
  14. }
  15. //----------------------------------------------------------------------------------------
  16. // TLtGrayAdorner::Free:
  17. //----------------------------------------------------------------------------------------
  18. #pragma segment MAAdornerNonRes
  19. pascal void TLtGrayAdorner::Free()
  20. {
  21.     if(fLtGrayPat)
  22.         DisposPixPat(fLtGrayPat);
  23.     fLtGrayPat = nil;
  24.     
  25.     if(fWhitePat)
  26.         DisposPixPat(fWhitePat);
  27.     fWhitePat = nil;
  28.     
  29. }
  30. //----------------------------------------------------------------------------------------
  31. // TLtGrayAdorner::ILtGrayAdorner:
  32. //----------------------------------------------------------------------------------------
  33. #pragma segment MAAdornerNonRes
  34. pascal void TLtGrayAdorner::ILtGrayAdorner()
  35. {
  36.     FailInfo    fi;
  37.     Boolean        wasPerm;
  38.     
  39.     // Initialize with our made up ID 'LGAD' and Do not free on deletion
  40.     
  41.     this->IAdorner('LGAD', kDontFreeOnDeletion);
  42.     
  43.     // now we'll create our light gray pattern for future use
  44.     // Note use of MacApp global "gRGBVeryLtGray"
  45.     
  46.     if (fi.Try()) {
  47.         wasPerm = PermAllocation(TRUE);            // Set perm. alloc. TRUE
  48.         fLtGrayPat = NewPixPat();                // Get the handle we need
  49.         FailMemError();
  50.         MakeRGBPat(fLtGrayPat,gRGBVeryLtGray);    // Create the Light Gray pattern
  51.         
  52.         CRGBColor white(65535, 65535, 65535);
  53.         fWhitePat = NewPixPat();
  54.         FailMemError();
  55.         MakeRGBPat(fWhitePat,white);
  56.  
  57.         wasPerm = PermAllocation(wasPerm);        // restore old state
  58.         fi.Success();
  59.     }
  60.     else {
  61.         if(fLtGrayPat)
  62.             DisposPixPat(fLtGrayPat);
  63.         fLtGrayPat = nil;
  64.         
  65.         if(fWhitePat)
  66.             DisposPixPat(fWhitePat);
  67.         fWhitePat = nil;
  68.         
  69.         fi.ReSignal();
  70.     }
  71. }
  72. //----------------------------------------------------------------------------------------
  73. // TLtGrayAdorner::Draw:
  74. //----------------------------------------------------------------------------------------
  75. #pragma segment MAAdornerRes
  76. pascal void TLtGrayAdorner::Draw(TView* itsView, const VRect& area)
  77. {
  78.     VRect itsAdornExtent,biggerArea;
  79.     CRect ltGrayArea,adornArea;
  80.     
  81.     TWindow *myWindow = itsView->GetWindow();
  82.     itsView->GetAdornExtent(itsAdornExtent);
  83.     itsView->ViewToQDRect(itsAdornExtent, adornArea);
  84.     
  85.     if(myWindow->IsActive() || myWindow->fFloats) {
  86.         if (!(area & itsAdornExtent).Empty())    // is there something to draw?
  87.         {
  88.             // First the light gray area - only draw what we have to draw here...
  89.             
  90.             itsView->ViewToQDRect(area, ltGrayArea);// convert to QD coord's 
  91.             FillCRect(ltGrayArea,fLtGrayPat);
  92.             
  93.             // Now the white border - draw this around the entire extent of the view
  94.             
  95.             PenPixPat(fWhitePat);
  96.             PenSize(2,2);
  97.             FrameRect(adornArea);    // Basic rectangle
  98.     
  99.             // Now a special deal for the case where we overlap the ResizeIcon
  100.             // If our superview is a window...        
  101.             
  102.             // ASSUMPTION ALERT: 
  103.             //    This code assumes that our view completely overlaps the
  104.             //    resize icon *AND* that the resize icon is a 16 x 16 square
  105.     
  106.             if((itsView->fSuperView != nil) && itsView->fSuperView->IsMemberClass(GetClassIDFromName("TWindow"))) {
  107.                 TWindow *theWindow = itsView->GetWindow();
  108.                 if (theWindow->fIsResizable) {    // And if this window has resize icon
  109.                     VRect    myExtent,hisExtent;
  110.                     itsView->GetExtent(myExtent);
  111.                     theWindow->GetExtent(hisExtent);
  112.                     hisExtent.top = hisExtent.bottom - 16;    // just the resize icon area
  113.                     hisExtent.left = hisExtent.right - 16;
  114.                     itsView->LocalToSuperVRect(myExtent);
  115.                     
  116.                     if (!(myExtent & hisExtent).Empty()) {    // AND we overlap it
  117.                         MoveTo(adornArea.left,adornArea.top);
  118.                         LineTo(adornArea.right-2,adornArea.top);
  119.                         LineTo(adornArea.right-2,adornArea.bottom-17);
  120.                         LineTo(adornArea.right-17,adornArea.bottom-17);
  121.                         LineTo(adornArea.right-17,adornArea.bottom-2);
  122.                         LineTo(adornArea.left,adornArea.bottom-2);
  123.                         LineTo(adornArea.left,adornArea.top);
  124.                     }    // if we overlap the resize icon
  125.                 }    // if there is a resize icon
  126.             }    // if the super view is a window
  127.         }    // if there is something to draw
  128.     }
  129.     else {    // window is inactive
  130.         FillCRect(adornArea,fWhitePat);
  131.     }
  132. }
  133.